home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / randomgn.zip / RANTSR.ASM < prev    next >
Assembly Source File  |  1991-06-28  |  3KB  |  133 lines

  1.  page ,132
  2. ;
  3. ;This TSR maintains a circular buffer of random numbers.  After the TSR is
  4. ;  loaded, it hooks to the multiplex interrupt.  To obtain n random numbers,
  5. ;  set al=n ; ah=aeh ; dx = 726eh ; es:di=buffer address for the numbers
  6. ;  INT 2F
  7. ;  Returns with al=ffh (success) or al=00 (not all n values returned)
  8. ;  dx = number of values returned
  9. ;  all other registers unchanged
  10. ;
  11. ;The TSR stores one random byte every time the keyboard interrupt (INT9)
  12. ;  is activated.  The byte is bits 9-2 of the current Timer 0 value.
  13. ;Note that n=0 can be used to determine whether or not the TSR has been
  14. ;  loaded
  15. ;
  16. ;Written by Joseph R Ahlgren, BBS 703-241-7980, CompuServe 70461,2340
  17. ;  This program is freeware.  It may be used without restriction, provided
  18. ;  the original source is acknowledged.
  19. ;  91/06/28
  20. ;
  21.  assume cs:cseg,ds:cseg,ss:cseg
  22. cseg segment para public 'code'
  23. FirstCode:
  24.  org 100h
  25. TableBase label byte
  26. LoadTSR:
  27.  jmp cs:[Last]
  28. Last dw LastCode
  29.  org 200h
  30. ByteLoc dw TableBase+00ffh
  31. LastByte dw Tablebase+00ffh
  32. Continue9 dd ?
  33. Continue2F dd ?
  34. INT9:
  35.  push ax
  36.  push bx
  37.  mov bx,cs:[ByteLoc]
  38.  inc bl
  39.  cmp bx,cs:[LastByte]
  40.  je exit
  41.  xor ax,ax
  42.  out   43h,al
  43.  in    al,40h
  44.  mov   ah,al
  45.  in    al,40h
  46.  xchg al,ah
  47.  shr ax,1
  48.  shr ax,1
  49.  mov cs:[ByteLoc],bx
  50.  mov cs:[bx],al
  51. exit:
  52.  pop bx
  53.  pop ax
  54.  jmp cs:[continue9]
  55. INT2F:
  56.  cmp ah,0aeh
  57.  jne exit2f
  58.  cmp dx,726eh ;'rn'
  59.  jne exit2f
  60.  push bx
  61.  push cx
  62.  mov dx,di
  63.  or al,al
  64.  jz DoneOK
  65.  mov cl,al
  66.  xor ch,ch
  67. Loop1:
  68.  cli
  69.  mov bx,cs:[LastByte]
  70.  cmp bx,cs:[ByteLoc]
  71.  je DoneShort
  72.  inc bl
  73.  mov al,cs:[bx]
  74.  mov cs:[LastByte],bx
  75.  sti
  76.  stosb
  77.  loop loop1
  78. DoneOK:
  79.  mov al,0ffh
  80. DoneDone:
  81.  sub di,dx
  82.  xchg dx,di
  83.  pop cx
  84.  pop bx
  85.  iret
  86. DoneShort:
  87.  xor al,al
  88.  jmp DoneDone
  89. exit2f:
  90.  jmp cs:[continue2f]
  91. LastCode:
  92.  mov ax,0ae00h
  93.  mov dx,0726eh
  94.  int 2fh
  95.  cmp al,0ffh
  96.  jnz NotLoaded
  97.  or dx,dx
  98.  jz AlreadyLoaded
  99. NotLoaded:
  100.  mov ax,3509h
  101.  int 21h  ;get int 9
  102.  mov [word ptr Continue9],bx
  103.  mov [word ptr Continue9+2],es
  104.  mov ax,2509h
  105.  mov dx,offset INT9
  106.  int 21h  ;link to INT9
  107.  mov ax,352Fh
  108.  int 21h  ;get int 2F
  109.  mov [word ptr Continue2F],bx
  110.  mov [word ptr Continue2F+2],es
  111.  mov ax,252Fh
  112.  mov dx,offset INT2F
  113.  int 21h  ;link to INT2F
  114.  mov dx,offset Success
  115.  mov ah,9
  116.  int 21h
  117.  mov ax,3100h  ;TSR
  118.  mov dx,(LastCode+15-FirstCode)/16
  119.  int 21h  ;TSR
  120. AlreadyLoaded:
  121.  mov dx,offset Already
  122.  mov ah,9
  123.  int 21h
  124.  mov ax,4c01h
  125.  int 21h
  126. Success db 0dh,0ah,0ah,'RANTSR loaded and linked to INT 2F',0ah,0dh
  127.         db ' Joseph R Ahlgren, BBS 703-241-2661',0ah,0dh,0ah,'$'
  128. Already db 0dh,0ah,0ah,'RANTSR already loaded',0ah,0dh,0ah,'$'
  129. cseg ends
  130.  end LoadTSR
  131.  
  132.  
  133.